package com.jpa_demo.repositories;

import com.jpa_demo.entity.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<User,Integer> , JpaSpecificationExecutor<User> {


    @Modifying
    @Query("UPDATE User u SET u.name = :name WHERE u.id = :id")
    int updateUser(@Param("name") String name1, @Param("id") Integer id2);


    @Modifying
    @Query("DELETE FROM User u WHERE u.id = :id ")
    int deleteById(@Param("id") int id);

// jpa自动生成的sql
    User findByName(String name);
}
